from expression import expression
import sys
sys.path.append(sys.path[0] + "/../LLVM")
from llvmhelper import llvmHelper
from commonRoutines import commonRoutines

class integer(expression):
	def __init__(self,val):
		self.val = val
		if(type(val) != type(0)):
			print "Int incorrectly intialized with a " + str(type(val))
	def evaluate(self, env):
		return self.val
		
	def toLLVM(self, helper): # do we want to deal with constants in if() statements?
		helper.descend("integer")
		helper.ascend(str(self.val << 2))
		
	def __str__(self):
		return "integer(" + str(self.val) + ")"

	def traverse(self, helper):
		pass

class flp(expression):
	def __init__(self,val):
		self.val = float(val)
		if(type(self.val) != type(0.0)):
			print "Floating-Point incorrectly intialized with a " + str(type(val))
			
	def evaluate(self, env):
		return self.val
		
	def toLLVM(self, helper):
		helper.descend("flp")
		c = commonRoutines(helper)
		helper.setLabel(helper.getLastLabel())
		f = c.createFloat(self.val,False,True,True)
		#sys.stderr.write("EndVals: " + f + "\n")
		helper.ascend(f)
		
	def __str__(self):
		return "flp(" + str(self.val) + ")"

	def traverse(self, helper):
		pass

class boolean(expression):
	def __init__(self,val):
		self.val = val
		if(type(val) != type(1==1)):
			print "Boolean incorrectly intialized with a " + str(type(val))
	def evaluate(self, env):
		return self.val
	
	def toLLVM(self, helper):
		helper.descend("boolean")
		# 11 marker
		# 111 true = 7
		# 011 false = 3
#		print "val: ", self.val
		if(self.val):
			stringVal = "7"
		else:
			stringVal = "3"
		helper.setLabel(helper.getLastLabel())	
		helper.ascend(stringVal)	
		
	def __str__(self):
		return "boolean(" + str(self.val) + ")"

	def traverse(self, helper):
		pass

class void(expression):
	def evaluate(self, env):
		return self
		
	def toLLVM(self, helper):
		helper.descend("void")
		helper.setLabel(helper.getLastLabel())
		helper.ascend(2)
		
	def __str__(self):
		return "void()"

	def traverse(self, helper):
		pass

